package com.deke.home.controller;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.deke.entity.TbHeadNav;
import com.deke.home.dao.TbHeadNavDao;
import com.deke.home.service.TbHeadNavService;
import com.deke.home.vo.TbHeadNavVo;
import com.deke.home.vo.TbZoneVo;
import com.deke.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author ：ludi（206913808@qq.com）
 * @date ：Created in 2022/12/6 13:05
 * @description：头部导航
 * @modified By：
 * @version:
 */
@Api(tags = "头部导航")
@RestController
@RequestMapping("/home/head")
public class TbHeadNavController {

    @Resource
    private TbHeadNavService tbHeadNavService;


    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示的条数")
    })
    @PostMapping("getAllHeadNav/{currentPage}/{pageSize}")
    public Result<IPage<TbHeadNav>> getAllHeadNav(@PathVariable(required = true, value = "currentPage") Integer current, @PathVariable(required = true) Integer pageSize, @RequestBody TbHeadNavVo tbHeadNavVo) {
        return tbHeadNavService.queryByConditionPage(current, pageSize, tbHeadNavVo);
    }



    @ApiOperation(value = "删除操作")
    @PostMapping("deleteHeadNav")
    public Result deleteHeadNav(TbHeadNav tbHeadNav, @RequestBody Map map) {
        tbHeadNav.setIsDisable("1");
        tbHeadNav.setIsDelete("1");
        tbHeadNavService.deleteHeadNav(tbHeadNav, Convert.toInt(map.get("headId")));
        return new Result(2000, "删除成功");
    }



    @ApiOperation(value = "添加、修改")
    @PostMapping("addHeadNav")
    public Result addHeadNav(@RequestBody TbHeadNav tbHeadNav) {
        if (ObjectUtil.isNotEmpty(tbHeadNav.getHeadId())) {
            return tbHeadNavService.updateHeadNav(tbHeadNav);
        } else {
            tbHeadNav.setIsDelete("0");
            tbHeadNav.setIsDisable("0");
            return tbHeadNavService.addHeadNav(tbHeadNav);
        }
    }



    @ApiOperation(value = "改变状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "headId",value = "id"),
            @ApiImplicitParam(name = "isDisable",value = "状态(0或1)")
    })
    @PostMapping("changeStatus/{headId}/{isDisable}")
    public Result changeStatus(@PathVariable Integer headId, @PathVariable String isDisable) {
        return tbHeadNavService.changeStatus(headId, isDisable);
    }
}